import { View } from "../../../mvc/core/View";
import { Language } from "../../../../extend/language/Language";
import { SPanicBuyRefreshMsg } from "../../../../Message/Game/SPanicBuyRefreshMsg";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { TilePanel } from "../equipment/TilePanel";
import { PreferenRender } from "./PreferenRender";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SPanicBuyItemMsg } from "../../../../Message/Game/SPanicBuyItemMsg";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SPanicBuyShopForMsg } from "../../../../Message/Game/SPanicBuyShopForMsg";
type int = number;
//class PreferenPanel
    
    export  class PreferenPanel extends View
    {
        constructor()
        {
            super();
            this._tips = Language.getString(53007);
            this.panicBuyItems = [];
            this.createChildren();
            return;
        }

        public updatePanicBuyItemMsg(arg1: SPanicBuyRefreshMsg): void
        {
            this.initData(arg1);
            this.updateTips();
            return;
        }

        protected initData(arg1: SPanicBuyRefreshMsg): void
        {
            this.refreshMsg = arg1;
            if (arg1) 
            {
                this.panicBuyItems = arg1.panicBuyItems;
                this.itemAmount = this.panicBuyItems.length;
                this.panicBuyShop = arg1.panicBuyShop;
                if (arg1.panicBuyShop) 
                {
                    this.beginTime = arg1.panicBuyShop.beginTime;
                    this.endTime = arg1.panicBuyShop.endTime;
                }
                if (this._timeTxtView) 
                {
                    this._timeTxtView.setLeftTime(this.panicBuyShop.leftSeconds);
                }
            }
            this.updateProvider();
            return;
        }

        protected updateTips(): void
        {
            this._tipTxt.htmlText = this._tips;
            return;
        }

        protected createChildren(): void
        {
            this._preperenBg = ResouceConst.getScaleBitmap("PreperenBg");
            this._preperenBg.width = 235;
            this._preperenBg.height = 344;
            this.addChild(this._preperenBg);
            this._preperenTitle = new Object /* flash.display.Bitmap */();
            this._preperenTitle.x = 40;
            this._preperenTitle.y = 5;
            this.addChild(this._preperenTitle);
            LoaderHelp.addResCallBack(ResFileConst.shopMall, this.updatePreperenTitle);
            ObjCreate.createBg(5, 35, 190, 1, this, ImagesConst.SeptalLine);
            ObjCreate.createBg(0, 40, 220, 22, this, ImagesConst.RemainningTimeBg);
            ObjCreate.createTextField(Language.getString(90226), 35, 41, 140, 20, this, new GTextFormat(FontUtil.songtiName, 14, 65280));
            this._timeTxtView = new SecTimerView();
            this._timeTxtView.mouseEnabled = false;
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            loc1.align = flash.text.TextFormatAlign.LEFT;
            this._timeTxtView.defaultTextFormat = loc1;
            this._timeTxtView.filters = [FilterConst.glowFilter];
            this._timeTxtView.setParse(Language.getString(53084));
            ObjCreate.setObjAttri(this._timeTxtView, 105, 41, 150, 25, this);
            this._itemListPanel = new TilePanel();
            this._itemListPanel.horizontalGap = 2;
            this._itemListPanel.setSize(220, 225);
            this._itemListPanel.columnWidth = 220;
            this._itemListPanel.rowHeight = 75;
            this._itemListPanel.setStyle("cellRenderer", PreferenRender);
            this._itemListPanel.move(5, 65);
            this.addChild(this._itemListPanel);
            this._backInput = ObjCreate.createGTextInput(60, 273, 110, 20, this);
            this._backInput.editable = false;
            this._backInput.visible = false;
            this._getBackBtn = ObjCreate.createGButton(Language.getString(53008), 175, 273, 50, 20, this, "Button");
            this._getBackBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBackBtnClickHandler);
            this._getBackBtn.visible = false;
            this._tipTxt = ObjCreate.createTextField(this._tips, 5, 290, 235, 40, this, GlobalStyle.textFormat2);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.multiline = true;
            this._tipTxt.wordWrap = true;
            this._tipTxt.mouseEnabled = false;
            return;
        }

        protected updateProvider(): void
        {
            var loc1=null;
            var loc2=0;
            if (this.itemAmount > 0) 
            {
                loc1 = new DataProvider();
                loc2 = 0;
                while (loc2 < this.itemAmount) 
                {
                    loc1.addItem({"panicBuyShop": this.panicBuyShop, "panicBuyItemMsg": this.panicBuyItems[loc2]});
                    ++loc2;
                }
                this._itemListPanel.dataProvider = loc1;
            }
            else 
            {
                this._itemListPanel.dataProvider = new DataProvider();
            }
            return;
        }

        public refreshDataProvider(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            if (typeof arg1 === "spanicbuyitemmsg") 
            {
                loc1 = arg1 as SPanicBuyItemMsg;
                loc2 = this._itemListPanel.dataProvider.toArray();
                loc3 = 0;
                while (loc3 < loc2.length) 
                {
                    loc4 = loc2[loc3].panicBuyItemMsg as SPanicBuyItemMsg;
                    if (loc1.itemCode == loc4.itemCode) 
                    {
                        this._itemListPanel.dataProvider.replaceItem({"panicBuyShop": this.panicBuyShop, "panicBuyItemMsg": loc1}, loc2[loc3]);
                    }
                    ++loc3;
                }
            }
            else if (typeof arg1 === "spanicbuyrefreshmsg") 
            {
                this.updatePanicBuyItemMsg(arg1 as SPanicBuyRefreshMsg);
            }
            return;
        }

        public updateBackInput(arg1: string): void
        {
            this._backInput.text = arg1;
            return;
        }

        public get refreshMsg(): SPanicBuyRefreshMsg
        {
            return this._refreshMsg;
        }

        public set refreshMsg(arg1: SPanicBuyRefreshMsg)
        {
            this._refreshMsg = arg1;
            return;
        }

        protected onGetBackBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Number(this._backInput.text);
            if (loc1 < 1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(53009));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallGetCostReturn));
            return;
        }

        /* internal  */updatePreperenTitle(): void
        {
            this._preperenTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.PreperenTitle);
            return;
        }

        protected /* var */_preperenTitle: Object /* flash.display.Bitmap */;

        protected /* var */_preperenBg: ScaleBitmap;

        protected /* var */_timeTxtView: SecTimerView;

        protected /* var */_tipTxt: Object /* flash.text.TextField */;

        protected /* var */_itemListPanel: TilePanel;

        protected /* var */_backInput: GTextInput;

        protected /* var */_getBackBtn: GButton;

        protected /* var */_refreshMsg: SPanicBuyRefreshMsg;

        protected /* var */_tips: string;

        public /* var */panicBuyItems: Array<any>;

        protected /* var */beginTime: Date;

        protected /* var */endTime: Date;

        protected /* var */itemAmount: int=0;

        protected /* var */panicBuyShop: SPanicBuyShopForMsg;
    }
